/*
Authors: Eli Yucht 300388949 and Lior Fass 300069705
Project: Hamming
Description: Socket Functions - Based on "introduction to Operating Systems course"

some functions declarations and implementations are base on the code that
provided by the course "introduction to Operating Systems course" team (that was writen by Amnon Drory.)
*/

#ifndef SOCKET_TOOLS_H
#define SOCKET_TOOLS_H

#define _WINSOCK_DEPRECATED_NO_WARNINGS // for inet_addr()
#pragma comment(lib,"Ws2_32.lib")

#include <winsock2.h>
#include <iostream>

using namespace std;

#define MAX_QUEUE 1
#define DEFAULT_BUFLEN 65536 // 2^16

/*This enum group contain 3 possible options regarding to send() and recv() function:

	TRNS_FAILED - an error occurred during the send or receive procedure
	TRNS_DISCONNECTED - The connection has been gracefully closed
	TRNS_SUCCEEDED - successed to send/recv the bytes to/from the connected socket
	
*/
typedef enum { TRNS_FAILED, TRNS_DISCONNECTED, TRNS_SUCCEEDED } TransferResult_t;

// Socket_tool class declaration
class Socket_tool
{
public:
	static int WinSock_Init();
	static SOCKET Create_Socket_and_Listen(char* name, unsigned short port_number);
	static TransferResult_t SendBuffer(const char* Buffer, int BytesToSend, SOCKET socket_for_write);
	static SOCKET Connect_Channel(char* channel_ip_addr, unsigned short channel_port);
	static TransferResult_t SendString(const char *Str, SOCKET sd);
	static TransferResult_t ReceiveBuffer(char* OutputBuffer, int BytesToReceive, int *RemainingBytesToReceive, SOCKET sd);
	static TransferResult_t ReceiveString(char** OutputStrPtr, SOCKET sd);
};




#endif // SOCKET_TOOLS_H